package com.meihua.shellapp.activity.wallet;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.lzy.okgo.OkGo;
import com.meihua.shellapp.R;
import com.meihua.shellapp.base.BaseActivity;
import com.meihua.shellapp.bean.IncomeBean;
import com.meihua.shellapp.databean.IncomeDataBean;
import com.meihua.shellapp.utils.DateUtils;
import com.meihua.shellapp.utils.MyStringCallBack;
import com.meihua.shellapp.utils.ToastUtils;
import com.meihua.shellapp.utils.URL;

import butterknife.Bind;

/**
 * 工资条详情
 * 作者：lc on 2017/10/16.
 * 邮箱：lc0607live@163.com
 */

public class SalaryDetailsActivity extends BaseActivity {

    @Bind(R.id.tv_title)
    TextView tv_title;//标题
    @Bind(R.id.iv_top_left)
    ImageView iv_top_left;//返回

    @Bind(R.id.tv_time)
    TextView tv_time;//时间
    @Bind(R.id.tv_initial_service)
    TextView tv_initial_service;//首期
    @Bind(R.id.tv_renewal_service)
    TextView tv_renewal_service;//续期
    @Bind(R.id.tv_manage_interest)
    TextView tv_manage_interest;//管理利益
    @Bind(R.id.tv_bred_interest)
    TextView tv_bred_interest;//育成利益
    @Bind(R.id.tv_debit)
    TextView tv_debit;//其他加扣款
    @Bind(R.id.tv_deduction)
    TextView tv_deduction;//扣税金额
    @Bind(R.id.tv_actual_pay)
    TextView tv_actual_pay;//合计

    private String id;
    private IncomeDataBean data;

    @Override
    public int getLayoutId() {
        return R.layout.activity_salary_details;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        id = getIntent().getStringExtra("id");
        tv_title.setVisibility(View.VISIBLE);
        tv_title.setText("工资条详情");
        iv_top_left.setVisibility(View.VISIBLE);
        iv_top_left.setOnClickListener(this);
    }

    private void bindData() {
        tv_time.setText(DateUtils.getInstance().getTimeYMDHM(data.getTime()));
        tv_initial_service.setText(data.getInitial_service());
        tv_renewal_service.setText(data.getRenewal_service());
        tv_manage_interest.setText(data.getManage_interest());
        tv_bred_interest.setText(data.getBred_interest());
        tv_debit.setText(data.getDebit());
        tv_deduction.setText(data.getDeduction());
        tv_actual_pay.setText(data.getOn_line());
    }

    @Override
    public void createLoadData() {
        super.createLoadData();
        getData();
    }

    private void getData() {
        OkGo.<String>post(URL.getUrl().GETSALARYINFO)
                .params("id", id)
                .execute(new MyStringCallBack<IncomeBean>(null) {
                    @Override
                    public void onSuccessData(IncomeBean bean) {
                        super.onSuccessData(bean);
                        if (bean.getCode() == 1) {
                            data = bean.getData();
                            bindData();
                        } else {
                            ToastUtils.getInstance().showToast(bean.getMsg());
                        }
                    }
                });
    }
}
